<template>
  <el-container>
    <el-header>
      <div class="left-panel">
        <el-button v-if="$AUTH('content:cmsContent:add')" type="primary" icon="el-icon-plus" @click="add"></el-button>
      </div>
      <div class="right-panel">
        <div class="right-panel-search">
          <!-- 日期时间范围 -->
          <el-date-picker v-model="search.createTime" type="datetimerange" value-format="YYYY-MM-DD HH:mm:ss" start-placeholder="开始日期" end-placeholder="结束日期" style="width: 100%;"></el-date-picker>
          <el-input v-model="search.cmsContentId" placeholder="内容" clearable></el-input>
          <el-input v-model="search.contentTypeId" placeholder="类型" clearable></el-input>
          <el-input v-model="search.departmentId" placeholder="部门店铺" clearable></el-input>
          <el-input v-model="search.customerId" placeholder="个人用户发布" clearable></el-input>
          <el-input v-model="search.typePath" placeholder="新闻分类路径" clearable></el-input>
          <el-input v-model="search.regionPath" placeholder="发布区域路径" clearable></el-input>
          <el-input v-model="search.categoryPath" placeholder="发布-电商产品栏目路径" clearable></el-input>
          <el-input v-model="search.contentCode" placeholder="内容编码" clearable></el-input>
          <el-input v-model="search.contentTitle" placeholder="标题" clearable></el-input>
          <el-input v-model="search.subtitle" placeholder="副标题" clearable></el-input>
          <el-input v-model="search.display" placeholder="1已发布 2待审核 0失效 3审核不通过 4过期(已下架)" clearable></el-input>
          <el-input v-model="search.contentValue" placeholder="内容" clearable></el-input>
          <el-input v-model="search.issueTime" placeholder="发行时间" clearable></el-input>
          <el-input v-model="search.expireTime" placeholder="过期下架时间" clearable></el-input>
          <el-input v-model="search.createTime" placeholder="创建时间" clearable></el-input>
          <el-input v-model="search.keyWords" placeholder="seo引擎关键字" clearable></el-input>
          <el-input v-model="search.description" placeholder="seo引擎描述" clearable></el-input>
          <el-input v-model="search.imgUrl" placeholder="标题宣传媒体" clearable></el-input>
          <el-input v-model="search.withMedia" placeholder="1 0是否有媒体图片" clearable></el-input>
          <el-input v-model="search.isTop" placeholder="是否置顶 购买置顶 按置顶金额降序" clearable></el-input>
          <el-input v-model="search.url" placeholder="自定义连接" clearable></el-input>
          <el-input v-model="search.toType" placeholder="1pc端 2移动客户端 3综合客户端" clearable></el-input>
          <el-input v-model="search.seq" placeholder="降序" clearable></el-input>
          <el-input v-model="search.collectionCount" placeholder="收藏数量" clearable></el-input>
          <el-input v-model="search.tagCount" placeholder="称赞数量" clearable></el-input>
          <el-input v-model="search.commentCount" placeholder="评论数量" clearable></el-input>
          <el-input v-model="search.lookCount" placeholder="查阅数量" clearable></el-input>
          <el-input v-model="search.membershipLevel" placeholder="会员等级限制" clearable></el-input>
          <el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
        </div>
      </div>
    </el-header>
    <el-main class="nopadding">
      <scTable ref="table" :apiObj="apiObj" row-key="cmsContentId" @selection-change="selectionChange" stripe>
        <el-table-column type="selection" width="50"></el-table-column>
        <el-table-column label="内容" prop="cmsContentId" width="150"></el-table-column>
        <el-table-column label="类型" prop="contentTypeId" width="150"></el-table-column>
        <el-table-column label="部门店铺" prop="departmentId" width="150"></el-table-column>
        <el-table-column label="个人用户发布" prop="customerId" width="150"></el-table-column>
        <el-table-column label="新闻分类路径" prop="typePath" width="150"></el-table-column>
        <el-table-column label="发布区域路径" prop="regionPath" width="150"></el-table-column>
        <el-table-column label="发布-电商产品栏目路径" prop="categoryPath" width="150"></el-table-column>
        <el-table-column label="内容编码" prop="contentCode" width="150"></el-table-column>
        <el-table-column label="标题" prop="contentTitle" width="150"></el-table-column>
        <el-table-column label="副标题" prop="subtitle" width="150"></el-table-column>
        <el-table-column label="1已发布 2待审核 0失效 3审核不通过 4过期(已下架)" prop="display" width="150"></el-table-column>
        <el-table-column label="内容" prop="contentValue" width="150"></el-table-column>
        <el-table-column label="发行时间" prop="issueTime" width="150"></el-table-column>
        <el-table-column label="过期下架时间" prop="expireTime" width="150"></el-table-column>
        <el-table-column label="创建时间" prop="createTime" width="150"></el-table-column>
        <el-table-column label="seo引擎关键字" prop="keyWords" width="150"></el-table-column>
        <el-table-column label="seo引擎描述" prop="description" width="150"></el-table-column>
        <el-table-column label="标题宣传媒体" prop="imgUrl" width="150"></el-table-column>
        <el-table-column label="1 0是否有媒体图片" prop="withMedia" width="150"></el-table-column>
        <el-table-column label="是否置顶 购买置顶 按置顶金额降序" prop="isTop" width="150"></el-table-column>
        <el-table-column label="自定义连接" prop="url" width="150"></el-table-column>
        <el-table-column label="1pc端 2移动客户端 3综合客户端" prop="toType" width="150"></el-table-column>
        <el-table-column label="经度" prop="longitude" width="150"></el-table-column>
        <el-table-column label="纬度" prop="latitude" width="150"></el-table-column>
        <el-table-column label="降序" prop="seq" width="150"></el-table-column>
        <el-table-column label="收藏数量" prop="collectionCount" width="150"></el-table-column>
        <el-table-column label="称赞数量" prop="tagCount" width="150"></el-table-column>
        <el-table-column label="评论数量" prop="commentCount" width="150"></el-table-column>
        <el-table-column label="查阅数量" prop="lookCount" width="150"></el-table-column>
        <el-table-column label="会员等级限制" prop="membershipLevel" width="150"></el-table-column>
        <el-table-column label="" prop="deleted" width="150"></el-table-column>
<!--    <el-table-column label="创建时间" prop="createTime" width="150" :formatter="formatDate"></el-table-column>-->
        <el-table-column label="操作" fixed="right" align="right">
          <template #default="scope">
            <el-button v-if="$AUTH('content:cmsContent:edit')" type="text" size="small" @click="table_edit(scope.row, scope.$index)">编辑</el-button>
            <el-divider direction="vertical"></el-divider>
            <el-button v-if="$AUTH('content:cmsContent:del')" type="text" size="small" @click="table_del(scope.row, scope.$index)">删除</el-button>
          </template>
        </el-table-column>
      </scTable>
    </el-main>
  </el-container>

  <cmsContentEdit-dialog v-if="dialog.cmsContentEdit" ref="cmsContentEditDialog" @success="handleSaveSuccess" @closed="dialog.cmsContentEdit=false"></cmsContentEdit-dialog>
</template>

<script>
  import contentAPI from '@/api/content/cmsContent';
  import cmsContentEditDialog from './cmsContentEdit';//1--导入
  export default {
    name: 'cmsContent',
    components: {
        cmsContentEditDialog//2发布
    },
    data() {
      return {
        dialog: {
          cmsContentEdit: false
        },
        apiObj: contentAPI.cmsContent.list,
        selection: [],
        search: {
          keyword: null,
          createTime: null
        }
      }
    },
    methods: {
      //添加
      add(){
        this.dialog.cmsContentEdit = true
        this.$nextTick(() => {
          this.$refs.cmsContentEditDialog.open()
        })
      },
      //编辑
      table_edit(row){
        this.dialog.cmsContentEdit = true
        this.$nextTick(() => {
          this.$refs.cmsContentEditDialog.open('edit').setData(row)
        })
      },
      //删除
      async table_del(row){
        var confirm = await this.$confirm('确定删除选中的项吗？', '提示', {
          confirmButtonText: 'ok',
          type: 'warning'
        }).catch(() => {})
        if(confirm !== 'confirm'){
          return false;
        }
        var res = await contentAPI.cmsContent.delete.delete(row.cmsContentId);
        if(res.code === 2000){
          this.$refs.table.refresh();
          this.$message.success("删除成功");
        }else{
          this.$alert(res.message, "提示", {type: 'error'});
        }
      },
      //表格选择后回调事件
      selectionChange(selection){
        this.selection = selection;
      },
      //搜索
      upsearch(){
        this.$refs.table.upData(this.search);
      },
      //本地更新数据
      handleSaveSuccess(){
        this.$refs.table.refresh();
      },
      handlePermissionSuccess(){
        this.$refs.table.refresh();
      },
      handleDataSuccess(){
        this.$refs.table.refresh();
      },
      formatDate(row,column) {// 获取单元格数据
        let data = row[column.property];
        if(data == null) {
          return null;
        }
        let dt = new Date(data);
        return dt.getFullYear() + '-' + (dt.getMonth() + 1) + '-' + dt.getDate() + ' ' + dt.getHours() + ':' + dt.getMinutes() + ':' + dt.getSeconds();
      },
    }
  }
</script>
<style>
</style>
